import type { IQuery, IResponse, TableResponse } from '@/api/config/types';
import axios from 'axios';

export interface GoodsCategory {
  categoryId?: string;
  categoryName: string;
  status?: string;
  deptId?: string;
  createBy?: string;
  createTime?: string;
  updateBy?: string | null;
  updateTime?: string | null;
}

const prefix = '/goods/category';

export const listCategory = (query?: IQuery) => {
  return axios.get<TableResponse<GoodsCategory>>(`${prefix}/list`, { params: query });
};

export const queryCategory = (query?: Partial<IQuery>) => {
  return axios.get<IResponse<GoodsCategory[]>>(`${prefix}/query`, { params: query });
};

export const addCategory = (data: Partial<GoodsCategory>) => {
  return axios.post<IResponse<GoodsCategory>>(`${prefix}`, data);
};

export const getCategoryDetail = (id?: string) => {
  return axios.get<TableResponse<GoodsCategory>>(`${prefix}/${id}`);
};

export const updateCategory = (data?: Partial<GoodsCategory>) => {
  return axios.put<IResponse<GoodsCategory>>(`${prefix}`, data);
};

export const deleteCategory = (ids: (string | number)[]) => {
  return axios.delete<IResponse<GoodsCategory>>(`${prefix}/${ids.join(',')}`);
};
